#ifndef CHAT_H
#define CHAT_H

#include <QWidget>

#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QHostAddress>

#include "listenserver.h"
//=========test==================
#include "../global.h"
//#include "../Protocol/msgheader.h"
//#include "global.h"
//===============================
namespace Ui {
    class Chat;
}

class Chat : public QWidget
{
    Q_OBJECT

public:
    explicit Chat(QWidget *parent = 0);
    ~Chat();

private:
    Ui::Chat *ui;

private slots:
    void on_m_pbSend_clicked();
    void on_m_pbClean_clicked();

    ///for listen server to deal connection
    void processNewConnection();
    bool startListen(QString ip = "10.253.172.13",int port = 5589);

    ///for client to deal with data arrived or connect or disconnect
    void processReadyRead();
    void processConnected();
    void processDisconnected();
    void processNewData(QByteArray data);

    ///connect signal and slot altogether
    void setConnect();
    ///for client,when connection change,need to connect the new ip
    void processConnectionChange(QString name = "yaoboyuan",QString ip = "10.253.172.13",int port = 5589);

public:

private:

    QTcpServer m_ListenSocket;        ///listen other user connect me and chat
    QTcpSocket *m_pClientConnection;  ///peer user

    QString m_Name;
    QString m_IP;
    int m_Port;

    QString m_PeerName;
    QString m_PeerIP;
    int m_PeerPort;

    bool m_bIsConnected;

};

#endif // CHAT_H
